package com.rui.patterns.iterator;

import java.util.List;

/**
 * @author : [锐神NO.3]
 * @version : [v1.0]
 * @className : StudentIteratorImpl
 * @createTime : [2022/2/24 16:36]
 * @description : [具体迭代器角色类]
 */

public class StudentIteratorImpl implements StudentIterator{

    private List<Student> list;

    public StudentIteratorImpl(List<Student> list) {
        this.list = list;
    }

    /**
     * 用来记录遍历时的位置
     */
    private int position = 0;

    /**
     * 判断是否还有元素
     */
    @Override
    public boolean hasNext() {
        return position < list.size();
    }

    /**
     * 获取下一个元素
     */
    @Override
    public Student next() {
        Student currentStudent = list.get(position);
        position++;
        return currentStudent;
    }
}
